{extend name="public/base" /}

{block name="content"}
<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">微信名</label>
        <div class="layui-input-block">
            <input type="text" name="wx_name" placeholder="请输入微信名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="username" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="0" title="男" checked="checked"><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>可借</div></div>
            <input type="radio" name="sex" value="1" title="女"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>不可借</div></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">充值总额</label>
        <div class="layui-input-block">
            <input type="text" name="money_count" placeholder="请输入金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="infoForm">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="js"}
<script>
    layui.use(['form', 'layedit'], function(){
        var $ = layui.jquery;
        var form = layui.form;
        var layedit = layui.layedit;
        var index = layedit.build('desc', {
            height: 200
        });
        form.verify({
            content: function (value) {
                return layedit.sync(index);
            }
        });

        //监听提交
        form.on('submit(infoForm)', function (data) {
            //console.log(data.field);
            $.ajax({
                url: '{:url("admin/money/add")}',
                type: 'post',
                data: data.field,
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function () {
                            window.location.href = data.url;
                        });
                    }else {
                        layer.open({
                            title: '添加失败',
                            content: data.msg,
                            icon: 5,
                            anim: 6
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}